import { storeBindingsBehavior } from 'mobx-miniprogram-bindings'
import { store } from '../../Store/Store'
 
Component({
  properties: {
    goods:"",
    cart:""
  },
  behaviors:[storeBindingsBehavior],
  storeBindings:{
    store,
    fields:['numA','numB','sum','cart',"getcart"],
    actions:['update',"addToCart"]
  },  
  methods:{
    gwc(){
      wx.reLaunch({
        url: '/pages/cart/cart',
      })
    },
    add:function(){
      const goods = {
        goods_id: this.properties.goods.goods_id,       // 商品的Id
        goods_name: this.properties.goods.goods_name,   // 商品的名称
        goods_price: this.properties.goods.goods_price, // 商品的价格
        goods_count:1,                           // 商品的数量
        goods_small_logo: this.properties.goods.goods_small_logo, // 商品的图片
        goods_state: true                         // 商品的勾选状态
      }
    this.setData({
      cart:  store.addToCart(goods)
    })
    wx.setStorageSync('cart', JSON.stringify(this.properties.cart))
      console.log(this.properties.cart)
    }
  },
  pageLifetimes:{
  onLoad(){
    console.log("进入组件")
  }
}
})